
package stcu.robjects;

import com.nvlled.route.*;
import stcu.Account;
import java.net.SocketAddress;

public class MemberAdd extends GroupObject {
    private String lastname;
    private String firstname;
    private String idNumber;
    private boolean newMember;
    private SocketAddress memberAddress;

    public MemberAdd(String gid, Account account) {
        super(gid);
        this.idNumber = account.getIDNumber();
        this.firstname = account.getFirstName();
        this.lastname = account.getLastName();
        newMember = true;
    }

    private MemberAdd(String gid, 
            Account account, 
            boolean isNew,
            SocketAddress address) {

        super(gid);
        this.idNumber = account.getIDNumber();
        this.firstname = account.getFirstName();
        this.lastname = account.getLastName();
        this.memberAddress = address;
        newMember = isNew;
    }

    public MemberAdd setOld() {
        Account account = new Account(idNumber, lastname, firstname);
        return new MemberAdd(getGroupId(), account, false, memberAddress);
    }

    public MemberAdd setAddress(SocketAddress address) {
        Account account = new Account(idNumber, lastname, firstname);
        return new MemberAdd(getGroupId(), account, newMember, address);
    }

    public SocketAddress getAddress() {
        return memberAddress;
    }

    public boolean isNewMember() {
        return newMember;
    }

    public Account getAccount() {
        return new Account(idNumber, lastname, firstname);
    }

    public String getIDNumber() {
        return idNumber;
    }

    public String getName() {
        return firstname + " " + lastname;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof MemberAdd) {
            return idNumber.equals(((MemberAdd) obj).getIDNumber());
        } else if (obj instanceof String) {
            return idNumber.equals((String) obj);
        }
        return false;
    }

    @Override
    public int hashCode() {
        return getIDNumber().hashCode();
    }

}
